package org.lds.hotkey.console.business.currhotkey.converter;

import org.lds.hotkey.console.business.currhotkey.entity.CurrHotKey;
import org.lds.hotkey.console.business.currhotkey.model.request.CurrHotKeyBaseCreateRequest;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class CurrHotKeyBaseCreateRequestToEntityConverter implements Converter<CurrHotKeyBaseCreateRequest, CurrHotKey> {

    @Override
    public CurrHotKey convert(CurrHotKeyBaseCreateRequest source) {
        return CurrHotKey.builder()
                .appId(source.getAppId())
                .key(source.getKey())
                .expireTime(source.getDuration() * 1000 + System.currentTimeMillis())
                .createTime(LocalDateTime.now())
                .build();
    }

}


